package com.dengke.springmybatis.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.dengke.springmybatis.dao.CityMapper;
import com.dengke.springmybatis.pojo.City;
import com.dengke.springmybatis.pojo.CityInfo;
import com.dengke.springmybatis.service.CityService;

@Service
public class CityServiceImpl implements CityService {

	@Autowired
	private CityMapper cityMapper;

	@Cacheable(value="hour",key="#id")
	public City getCity(int id) {
		System.out.println("调用Mapper");
		return cityMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<City> getTop100City() {
		List<City>list=cityMapper.selectTop100City();
		return list;
	}

	@Override
	public int insert(City city) {
		
		return cityMapper.insert(city);
	}

	@Override
	public List<String> selectCountryCode() {

		return cityMapper.selectCountryCode();
	}

	@Override
	public CityInfo GetCityInfoById(int id) {
		return cityMapper.selectCityInfoById(id);
	}

	@Override
	public City GetCityById(int id) {
		return cityMapper.selectCityById(id);
	}

	@Override
	@CacheEvict(value="hour",key="#city.getId()")
	public int updateCity(City city) {
		return cityMapper.updateByPrimaryKey(city);
	}


}
